package com.example.config;

import com.example.myweirdfunction.MyWeirdBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 一个最简单的 自动装配的配置类
 */
@ConditionalOnClass(MyWeirdBean.class)
@Configuration
@EnableConfigurationProperties(MyConfigurationProperties.class)
public class MyWeirdBeanAutoConfiguration {

    @Autowired
    private MyConfigurationProperties myConfigurationProperties;

    @Bean("bean1")
    @ConditionalOnMissingBean(MyWeirdBean.class)
    public MyWeirdBean getMyWeirdBean() {
        return new MyWeirdBean(myConfigurationProperties.getThings());
    }

}
